package com.ourteam.product.model.api;

import org.apache.commons.lang3.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.product.model.dao.IProductModelPropertyDAO;
import com.ourteam.product.model.dao.ProductModelPropertyDAOQueryBean;
import com.ourteam.product.model.domain.ProductModelPropertyBean;

public class ProductModelPropertySearchModel extends AbstractSearchModel<ProductModelPropertyDAOQueryBean> {

	private long id;

	private String isPrimaryKey;

	@Override
	public String getMappedDAOField(String aProperty) {
		return ProductModelPropertyBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(ProductModelPropertyDAOQueryBean queryBean) throws Exception {
		ProductModelPropertyDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		criteria.andObjectIdEqualTo(id);

		if (StringUtils.isNotBlank(isPrimaryKey)) {
			criteria.andIsPrimaryKeyEqualTo(isPrimaryKey);
		}

		if (queryBean.getSortProperties().isEmpty()) {
			queryBean.setSortProperty(IProductModelPropertyDAO.IsPrimaryKey,false);
		}
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getIsPrimaryKey() {
		return isPrimaryKey;
	}

	public void setIsPrimaryKey(String isPrimaryKey) {
		this.isPrimaryKey = isPrimaryKey;
	}

}
